home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6979 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: calloc help needed
  5. Date: 16 Feb 1996 22:15:22 GMT
  6. Organization: OpenVision
  7. Message-ID: <4g2vlq$n4k@spanky.pls.ov.com>
  8. References: <1996Feb15.125431.7751@leeds.ac.uk>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article 7751@leeds.ac.uk, csyamc@scs.leeds.ac.uk (A M Casey) writes:
  13. >I'm trying to allocate enough memory for an array of strings, defined as
  14. >char * MyArray[20].
  15. >the only manual entry I have for calloc says that it needs two values, the
  16. >number of elements, and the size of each, but how do I actually use it?
  17. >
  18. >MyArray = calloc(20,50);
  19. >
  20. >doesnt work, as far as I can tell calloc returns an int.
  21. >
  22. >ANy help would be greatly appreciated
  23. >
  24. >ANdy
  25.  
  26.  
  27. Like malloc(), calloc() returns a pointer to a memory area of the size
  28. that you specified.  How you use that pointer is strictly up to you.
  29.  
  30. One side effect of calloc() is that the memory set aside is initialized to
  31. all zeroes.
  32.  
  33. It's clear that you need to examine your manual entry more carefully.  It
  34. should have said something like:
  35.  
  36. void *calloc(unsigned nelem, unsigned elsize);
  37.  
  38. From the above you can tell that the function returns a pointer of undetermined
  39. type.  Further, the text in my manual (for malloc, calloc, realloc) says
  40. (in part):
  41.  
  42.      Each of the allocation routines returns a pointer  to  space
  43.      suitably  aligned  for  storage  of any type of object. Each
  44.      returns a NULL pointer if the request  cannot  be  completed
  45.      (see DIAGNOSTICS).
  46.  
  47.             Fletcher.Glenn@ov.com
  48.  
  49.